package com.lab03;


import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class TopPassword {
    private static final String SQL = "SELECT password  ,count(*)  from db_csdn.csdn GROUP BY password ORDER BY count(*) desc limit 10";

    public static void main(String[] args) throws SQLException, IOException {
        Connection connection = DBCPDatasource.getConnection();

        PreparedStatement preparedStatement = connection.prepareStatement(SQL);


    //
        long starTime = System.currentTimeMillis();
        ResultSet resultSet = preparedStatement.executeQuery(SQL);
        System.out.println("密码"+"\t\t\t\t\t"+"数量");

        while (resultSet.next()){

            String password = resultSet.getString("password");
            String count = resultSet.getString("count(*)");
            System.out.println(password+"\t\t\t\t"+count);

        }

        long endTime = System.currentTimeMillis();
        resultSet.close();
        preparedStatement.close();
        connection.close();
        System.out.println("共耗时"+(endTime-starTime)+"ms.");
    }
}

/*
        密码					数量
        123456789				235024
        12345678				212751
        11111111				76346
        dearbook				46054
        00000000				34952
        123123123				19986
        1234567890				17791
        88888888				15033
        111111111				6995
        147258369				5966
        共耗时388043ms.
        */
